package org.jash.sportnews2109.entity

import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import org.jash.sportnews2109.BR
import java.text.SimpleDateFormat
import java.util.Date
val sdf = SimpleDateFormat("yyyy-MM-dd")
data class Comment(
    var content: String,
    val createTime: Date,
    val id: Int,
    val nid: Int,
    var parentid: Int,
    val replays: List<Comment>,
    val uid: Int
) : BaseObservable() {
    var user:User = User(0, "", "")
    val timeString
        get() = sdf.format(createTime)
    val replayString:CharSequence
        get() {
            val builder = SpannableStringBuilder()
            builder.append("${user.username}:", ForegroundColorSpan(0xFF2962FF.toInt()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
            builder.append(content)
            return builder
        }
    @Bindable
    var parent:Comment? = null
        set(value) {
            field = value
            parentid = value?.id ?: 0
            notifyPropertyChanged(BR.parent)
        }
}